package day5;

import java.util.Scanner;

public class Main {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            StringBuilder str1 = new StringBuilder(in.nextLine());
            StringBuilder str2 = new StringBuilder(in.nextLine());
            int count = 0;
            for (int i = 0; i <= str1.length(); i++) {
                StringBuilder str = new StringBuilder(str1);
                str.insert(i,str2);
                if(isreserve(str)) {
                    count++;
                }
            }
            System.out.println(count);

        }
    }
    private static boolean isreserve(StringBuilder str) {
        int i = 0;
        int j = str.length()-1;
        while(i < j) {
            if(str.charAt(i) != str.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            String str1 = in.nextLine();
            String str2 = in.nextLine();
            int len = str1.length();
            int n = 0;
            for (int i = 0; i <= len; i++) {
                StringBuilder str = new StringBuilder(str1);
                str.insert(i, str2);
                StringBuilder tmp = new StringBuilder(str);
                StringBuilder str5 = tmp.reverse();
                if(str.toString().equals(str5.toString())) {
                    n++;
                }
            }
            System.out.println(n);
        }
    }

    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int n = in.nextInt();
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = in.nextInt();
            }
            int sum = 0;
            int maxSum = Integer.MIN_VALUE;
            for (int i = 0; i < n; i++) {
                sum += array[i];
                maxSum = Math.max(maxSum,sum);
                sum = sum < 0 ? 0 : sum;
            }
            System.out.println(maxSum);
        }
    }

    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int size = in.nextInt();
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = in.nextInt();
            }
            int sum = array[0];
            int max = array[0];
            for (int i = 1; i < size; i++) {
                sum = GetMax(sum + array[i],array[i]);
                if(sum >= max) {
                    max = sum;
                }
            }
            System.out.println(max);
        }
    }
    public static int GetMax(int a, int b){
        return (a) > (b) ? (a) : (b);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] arr = new int[n];
            for(int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int sum = 0;
            int max = Integer.MIN_VALUE;
            for(int i = 0; i < n; i++) {
                sum += arr[i];
                if(max < sum) {
                    max = sum;
                }
                if(sum < 0) {
                    sum = 0;
                }
            }
            System.out.println(max);
        }
    }
}
